import zipfile
import json


class PackInfo:

    def __init__(self, hapfile) -> None:
        if type(hapfile) == str:
            self.hapfile = zipfile.ZipFile(hapfile)
        else:
            self.hapfile = hapfile

        
        self.info = json.loads(self.hapfile.open('pack.info').read().decode(errors='ignore'))

    def summary(self):
        return self.info['summary']


    def packages(self):
        return self.info['packages']
    
    def app(self):
        return self.summary()['app']

    def version(self):
        return self.app()['version']['name']

    def bundleName(self):
        return self.app()['bundleName']